//index.js
//获取应用实例
var app = getApp()
Page({
    data: {

    },
    onLoad: function () {

    },
    onReady: function () {
        var _this = this;
        wx.login({
            success: function (res) {
                var args = {};
                args['code'] = res.code;
                args['appid'] = "wxdb4102ab0db1af27";
                args['secret'] = "a4f9ad1a2798a3750aee47f91637bfe1";
                args['grant_type'] = "authorization_code";
                wx.request({
                    url: app.config() + 'index/gettoken',
                    data: args,
                    header: {
                        'content-type': 'application/json'
                    },
                    success: function (res) {
                        wx.setStorage({
                            key: 'loginInfo',
                            data: res
                        })
                        var open_id = res.data.data.openid;
                        wx.request({
                            url: app.config()+'member/isAutoData',
                            data: {
                                open_id: open_id
                            },
                            header: {
                                'content-type': 'application/json'
                            },
                            success: function (res) {
                                if (res.data.status == '0') {
                                    wx.setStorage({
                                        key: 'm_data',
                                        data: res.data
                                    })
                                    _this.setData({
                                        show_m_data_btn: true
                                    })
                                }
                            }
                        })
                    }
                })
            }
        })
        _this.setData({
            show_m_data_btn: ""
        })
    }
})
